﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace FierceWar
{
	public class MouseInput
	{
		public static MouseState LastState;
		public static MouseState CurrentState;
		public static GraphicsDevice GraphicsDevice;
		public static GameWindow Window;

		public static bool IsLeftPress
		{
			get
			{
				return (CurrentState.LeftButton == ButtonState.Pressed);
			}
		}

		public static bool IsRightPress
		{
			get
			{
				return (CurrentState.RightButton == ButtonState.Pressed);
			}
		}

		public static bool IsLeftClick
		{
			get
			{
				return ((LastState.LeftButton == ButtonState.Pressed) &&
					(CurrentState.LeftButton == ButtonState.Released));
			}
		}

		public static bool IsRightClick
		{
			get
			{
				return ((LastState.RightButton == ButtonState.Pressed) &&
					(CurrentState.RightButton == ButtonState.Released));
			}
		}

		public static bool IsLeftButtonReleased
		{
			get
			{
				return ((LastState.LeftButton == ButtonState.Pressed) &&
					(CurrentState.LeftButton == ButtonState.Released));
			}
		}

		public static bool IsRightButtonReleased
		{
			get
			{
				return ((LastState.RightButton == ButtonState.Pressed) &&
					(CurrentState.RightButton == ButtonState.Released));
			}
		}

		private static int _lastScrollWheelValue;
		public static int LastScrollWheelValue
		{
			get
			{
				return LastState.ScrollWheelValue;
			}
		}

		private static int _currentScrollWheelValue;
		public static int CurrentScrollWheelValue
		{
			get
			{
				return CurrentState.ScrollWheelValue;
			}
		}

		public static Vector2 Position
		{
			get
			{
				return new Vector2(CurrentState.X, CurrentState.Y);
			}
		}

		public static bool IsOnScreen
		{
			get
			{
				if ((Position.X < 0) ||
				(Position.Y < 0) ||
				(Position.X > Window.ClientBounds.Width) ||
				(Position.Y > Window.ClientBounds.Height))
				{
					return false;
				}

				return true;
			}
		}

		public static bool ClickTop
		{
			get
			{
				return (IsLeftPress &&
					(CurrentState.Y <= (GraphicsDevice.Viewport.Height / 3)));
			}
		}

		public static bool ClickBottom
		{
			get
			{
				return (IsLeftPress &&
					(CurrentState.Y >= (2 * GraphicsDevice.Viewport.Height / 3)));
			}
		}

		public static bool ClickLeft
		{
			get
			{
				return (IsLeftPress &&
					(CurrentState.X <= (GraphicsDevice.Viewport.Width / 3)));
			}
		}

		public static bool ClickRight
		{
			get
			{
				return (IsLeftPress &&
					(CurrentState.X >= (2 * GraphicsDevice.Viewport.Width / 3)));
			}
		}

		public static void Update()
		{
			LastState = CurrentState;
			_lastScrollWheelValue = CurrentScrollWheelValue;
			CurrentState = Mouse.GetState();
			_currentScrollWheelValue = CurrentState.ScrollWheelValue;
		}
	}
}
